import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class TestRedis {

    public static void main(String[] args) {
        String pwd ="redis@WSX!QAZ1234XXX";
        //实例化Jedis
//        Jedis jedis = new Jedis("127.0.0.1",6379);
        //设置连接密码
      //  jedis.auth(pwd);
        //写入
        //jedis.set("str","v-str");
        //System.out.println("写入成功");

        //读取 如果报错的话,试试pom文件的jredis的版本调低一点
       // String uname = jedis.get("str");
       // System.out.println("读取redis中的userName 为: "+uname);

        //=======================
        //使用 JedisPoolConfig 工具类,释放资源
        //=======================
        Jedis jedis =null;
        JedisPoolConfig conf = new JedisPoolConfig();
        conf.setMaxActive(20);
        conf.setMaxIdle(10);
        conf.setMaxWait(1000);
        conf.setTestOnBorrow(true);

        JedisPool pool = new JedisPool(conf,
                "127.0.0.1",6379,2000,pwd);
        jedis = pool.getResource();
        String uname = jedis.get("str");
        System.out.println("JedisPoolConfig读取redis中的str 为: "+uname);
    }
}
